Two types of data-manipulation:
… but same syntax and in one dataframe.
PS: always an option, do (2) in SAS, Stata, etc. before reading and joining data (previous step).
# library(rgdal) # provides readOGR() to read in spatial data
# library(BelgiumMaps.StatBel)
# library(sf)
# library(tmap) # plot thematic map with qtm()
# library(dplyr) # general data-manipulation
# library(stringr) # string-operations str_sub()
# library(readr) # read CSV-file read_csv()
# load spatial data
raillines <- st_read(here('data/source/census_1851_raillines/1851EngWalesScotRail_Lines.shp')) %>%
clean_names()
## Reading layer `1851EngWalesScotRail_Lines' from data source `/home/rstudio/projects/historical-maps-r/data/source/census_1851_raillines/1851EngWalesScotRail_Lines.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1431 features and 2 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: 155368 ymin: 36976.83 xmax: 655241.1 ymax: 805911.3
## epsg (SRID): NA
## proj4string: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs
# load data-of-interest
# join spatial data and data-of-interest
districts_pop <- districts_pop %>%
mutate(pct_prof = tertiary_services_professions / total)
mapview(districts_pop, zcol = 'pct_prof')